// 源插件
import React, { Fragment, PureComponent } from 'react';
import { DateDiff, DateStamp, FormatnumberZero, Mover, NumberDivide } from '@/function.js';
// 视图插件
import { Button, Card, Divider, Form, message, Modal, notification } from 'antd';
// 外部组件
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import StandardTablePro from '@/components/UpgradeStandardTable/StandardTablePro';
import { connect } from 'dva';

// css OR less预编译器

// 图片

/**
 *  Describe:数据连接
 */

@connect(({ ubs, loading }) => ({
  ubs,
  loading: loading.models.ubsRule,
}))
@Form.create()
class UbsCreeper extends PureComponent {
  componentWillMount() {}

  /**
   *  Describe:当前状态
   */

  state = {
    listLoading: false, // 加载状态
    dataSourceTotal: {
      data: [],
      total: [],
      code: 0,
    },
    dataSourceAdd: {
      data: [],
      total: [],
      code: 0,
    },
    dataSourceReduce: {
      data: [],
      total: [],
      code: 0,
    },
    dataSourceOther: {
      data: [],
      total: [],
      code: 0,
    },
    row: {},
  };

  dataSourceChange() {
    const { dispatch } = this.props;
    const that = this;
    dispatch({
      type: 'ubs/GetUbsBankCrawlDetail',
      payload: 1,
      callback: res => {
        that.setState({
          dataSourceTotal: {
            title: res.date+` 瑞银爬虫明细`,
            code: 1,
            showHeader:false,
            titleTotal:false,
            data: [{name:'市值',value:res.list.marketValueSum},{name:'盈利',value:res.list.todayProfitSum}] ,
            total: [],
            columns: [
              {
                title: '',
                dataIndex: 'name',
                type: 'string',
              },
              {
                title: '',
                dataIndex: 'value',
                type: 'number',
              },
            ],
          },
          dataSourceAdd: {
            title: `瑞银新增列表`,
            code: 1,
            data: res.list.addList,
            total: [ 'todayProfit', 'marketValue'],
            columns: [
              {
                title: '代码',
                dataIndex: 'code',
                type: 'string',
                search: true,
              },
              {
                title: '今日收益',
                dataIndex: 'todayProfit',
                type: 'number',
                sorter: true,
              },
              {
                title: '成本价',
                dataIndex: 'costPrice',
                type: 'number',
                sorter: true,
              },
              {
                title: '市值',
                dataIndex: 'marketValue',
                type: 'number',
                sorter: true,
              },
            ],
          },
          dataSourceReduce: {
            title: `瑞银减少列表`,
            code: 1,
            data: res.list.reduceList,
            total: [ 'todayProfit', 'marketValue'],
            columns: [
              {
                title: '代码',
                dataIndex: 'code',
                type: 'string',
                search: true,
              },
              {
                title: '今日收益',
                dataIndex: 'todayProfit',
                type: 'number',
                sorter: true,
              },
              {
                title: '成本价',
                dataIndex: 'costPrice',
                type: 'number',
                sorter: true,
              },
              {
                title: '市值',
                dataIndex: 'marketValue',
                type: 'number',
                sorter: true,
              },
            ],
          },
          dataSourceOther: {
            title: `瑞银其它列表`,
            code: 1,
            data: res.list.otherList,
            total: [ 'todayProfit', 'marketValue'],
            columns: [
              {
                title: '代码',
                dataIndex: 'code',
                type: 'string',
                search: true,
              },
              {
                title: '今日收益',
                dataIndex: 'todayProfit',
                type: 'number',
                sorter: true,
              },
              {
                title: '成本价',
                dataIndex: 'costPrice',
                type: 'number',
                sorter: true,
              },
              {
                title: '市值',
                dataIndex: 'marketValue',
                type: 'number',
                sorter: true,
              },
            ],
          },
        });
      },
    });
  }

  render() {
    const { dataSourceTotal, dataSourceAdd, dataSourceReduce, dataSourceOther } = this.state;
    return (
      <PageHeaderWrapper>
        <Card>
          <div style={{width:'50%'}}>
          <StandardTablePro dataSource={dataSourceTotal}  />
          </div>
          <br/>
          <br/>
          <StandardTablePro dataSource={dataSourceAdd} />
          <br/>
          <br/>
          <StandardTablePro dataSource={dataSourceReduce} />
          <br/>
          <br/>
          <StandardTablePro dataSource={dataSourceOther} />
        </Card>
      </PageHeaderWrapper>
    );
  }

  componentDidMount() {
    this.dataSourceChange();
  }

  componentWillUnmount() {}
}

export default UbsCreeper;
